package com.example.superoa.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.Rplan;
import com.example.superoa.model.service.RplanService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class RplanController {
		@Autowired
		private RplanService planservice;	
		//查询所有		
		@PostMapping("select-plan")
		@ResponseBody
		public Map<String,Object> show(int page,int rows) {
			Map<String,Object> map = new HashMap<>();
			//先分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray j = planservice.biofindAllplan();
			int i=1;
			for (Object object : j) {
				JSONObject obj=(JSONObject)object;
				obj.put("plan", i);
				i++;
			}
			//总记录
			map.put("total", pg.getTotal());
			//页内容
			map.put("rows", j);
			return map;
		}		
		//点击查看详情显示
		@RequestMapping("plan-xiangq")
		@ResponseBody
		public JSONArray planxiangq(int rplanid) {
			return planservice.findByIdplan(rplanid);
		}		
		//启用、不启用
		@RequestMapping("rplan_qiyong")
		@ResponseBody
		public int qiyong(Integer id,Integer qi) {
			planservice.Qi(id,qi);
			return 1;
		}
		@RequestMapping("plan")
		@ResponseBody
		public JSONArray plan() {
			return planservice.biofindAllplan();
		}		
		/**新增
		 * @return
		 */
		@RequestMapping("rplans")
		@ResponseBody
		public String recruitaddprogram(Rplan plan,Integer dept_id,Integer postione_id,Integer staff_id) {
			planservice.addprogram(plan,staff_id,postione_id,dept_id);
			return "redirect:main-administrator:recruitprogram";				
		}	
		//初始化
		@RequestMapping("plans-allplan")
		@ResponseBody
		public JSONArray selectallplans(int rplanid) {		
			JSONArray json = planservice.findByIdplan(rplanid);
			return json;
		}
		//修改
		@RequestMapping("plans-bianjis")
		@ResponseBody
		public void xiugaiplan(int rplanid,String rplanname,Date rplanstart,Date rplanend, Date rplanexitstart,Date rplanexitend,
				String rplanway,BigDecimal rplanmoney,BigDecimal rplanexitmoney) {
			System.err.println("接收到"+rplanid+".."+rplanname+".."+rplanstart+".."+rplanend+".."+rplanexitstart+".."+rplanexitend
					+".."+rplanway+".."+rplanmoney+".."+rplanexitmoney);
			planservice.xiugaiplan(rplanid, rplanname, rplanstart, rplanend, rplanexitstart, rplanexitend,rplanway,rplanmoney,rplanexitmoney);
		}
}